**** --------------------------------------------------------*****
****
**** Control, Dispute, and Concentration of Land During Civil War: Evidence from Colombia
****
**** Replications Files ******
****
**** Created by Juan Carlos Muñoz, Sandra Johansson and Jose Fortue
****            January, 2023
**** --------------------------------------------------------*****

***---  Preliminars
	cap restore
	set more off
	clear all
	global tables_setup "cells(b(star fmt(3)) se(par([ ]) fmt(3)))  starlevels(* 0.10 ** 0.05 *** 0.01) label  eqlabels(none)  mlabels(none) collabels(none)  "

	
***-- Working path
global wp  "/Users/jcmunoz/Library/CloudStorage/OneDrive-UniversidadEAFIT/Projects_Terminados/2021_Paper_Uraba/Final_Submission_2023/Replication_Files/"
	
***---  Open main data sets
	cd $wp
	use "Munoz_etal_2023-Uraba.dta", clear

		
***--- Groups of variables
global geo "dist_carr dist_mar area_ha"
global displa "stad_recibidos stad_expulsados"

*** need packages ( if needed)
	*cap ssc install matmap
	*cap ssc install nearstat
	adopath + $wp
	
*** Spatial Statistical Analysis
	nearstat  mean_x mean_y, near(mean_x mean_y) distv(neardist) des(stat)
	local max_dist=r(nearest_max)
	gen cutoff1=`max_dist'
	gen cutoff2=`max_dist'
	gen cons=1

** Final Steps
	qui include "Labels_Munoz_etal_2023-Uraba.do"

xi i.mpio_mpio i.id_corre


*****************************************************
********************
***** Table 2. Descriptive Statistics
********************
*****************************************************

eststo clear
ereturn clear
mat N=J(5,17,0)
eststo: quietly estpost summarize gini_owner gini_land prop_mean_size prop_mean_plots indice_informalidad area_ha Disp_Disp_north Disp_Farc Disp_Define Disp_Disp_south dist_carr dist_mar recibidos expulsados mean_x mean_y neardist, listwise
local j=1
foreach i in gini_owner gini_land prop_mean_size prop_mean_plots indice_informalidad area_ha Disp_Disp_north Disp_Farc Disp_Define Disp_Disp_south dist_carr dist_mar recibidos expulsados mean_x mean_y neardist{
quietly sum `i', detail
mat N[1,`j']=r(N)
mat N[2,`j']=r(p25)
mat N[3,`j']=r(p50)
mat N[4,`j']=r(p90)
mat N[5,`j']=r(p99)
loca j=`j'+1
}
matrix colnames N =  gini_owner gini_land prop_mean_size prop_mean_plots indice_informalidad area_ha Disp_Disp_north Disp_Farc Disp_Define Disp_Disp_south dist_carr dist_mar recibidos expulsados mean_x mean_y neardist
estadd matrix N1=N[1,1...]
estadd matrix p25=N[2,1...]
estadd matrix p50=N[3,1...]
estadd matrix p90=N[4,1...]
estadd matrix p99=N[5,1...]

estout using "Munoz_etal_2023-Uraba-Table2.csv", cells("N1 mean(fmt(%9.3f)) sd(fmt(%9.3f)) p25(fmt(%9.3f)) p50(fmt(%9.3f)) p90(fmt(%9.3f))  p99(fmt(%9.3f))" ) label replace eqlabels(none)  mlabels(none)  collabels("Observations" "Mean" "Std. Deviation" "Q25" "Q50" "Q90" "Q99")  style(tab)  delimiter(",")     


*****************************************************
********************
***** Table 3. Land and Territorial Disputes: Results for Land Gini Indices
********************
*****************************************************

**** SD with spatial correlation
** Eq1
local j=1
foreach i in  gini_land gini_owner {
	cap drop epsilon window dis1 dis2
	x_ols mean_x mean_y cutoff1 cutoff2 `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc _Impio* cons, xreg(13) coord(2)
	mat sp=vecdiag(cov_dep)
	matmap sp V1_`j', map(sqrt(@))
	mat b1_`j'=e(b)
	cap drop epsilon window dis1 dis2
	x_ols mean_x mean_y cutoff1 cutoff2 `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar _Impio* _Iid* cons  , xreg(69) coord(2)
	mat sp=vecdiag(cov_dep)
	matmap sp V2_`j', map(sqrt(@))
	mat b2_`j'=e(b)
	local j=`j'+1
}

forvalue j=1/2 {
matrix colnames V1_`j' =  Disp_Disp_north Disp_Disp_south Disp_Define  Disp_Farc _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665  _Impio_mpio_837  _cons
matrix colnames V2_`j' =  Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar  _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665 _Impio_mpio_837 _Iid_corre_2 _Iid_corre_3 _Iid_corre_4 _Iid_corre_5 _Iid_corre_6 _Iid_corre_7 _Iid_corre_8 _Iid_corre_9 _Iid_corre_10 _Iid_corre_11 _Iid_corre_12 _Iid_corre_13 _Iid_corre_14 _Iid_corre_15 _Iid_corre_16 _Iid_corre_17 _Iid_corre_18 _Iid_corre_19 _Iid_corre_20 _Iid_corre_21 _Iid_corre_22 _Iid_corre_23 _Iid_corre_24 _Iid_corre_25 _Iid_corre_26 _Iid_corre_27 _Iid_corre_28 _Iid_corre_29 _Iid_corre_30 _Iid_corre_31 _Iid_corre_32 _Iid_corre_33 _Iid_corre_34 _Iid_corre_35 _Iid_corre_36 _Iid_corre_37 _Iid_corre_38 _Iid_corre_39 _Iid_corre_40 _Iid_corre_41 _Iid_corre_42 _Iid_corre_43 _Iid_corre_44 _Iid_corre_45 _Iid_corre_46 _Iid_corre_47 _Iid_corre_48 _Iid_corre_49 _Iid_corre_50 _Iid_corre_51 _Iid_corre_52 _Iid_corre_53 _Iid_corre_54
}

** t-stat
mat t_stat_1=J(2,13,0)
forvalue j=1/13 {
mat t_stat_1[1,`j']=b1_1[1,`j']/V1_1[1,`j']
mat t_stat_1[2,`j']=b1_2[1,`j']/V1_2[1,`j']
}
mat t_stat_2=J(2,69,0)
forvalue j=1/13 {
mat t_stat_2[1,`j']=b2_1[1,`j']/V2_1[1,`j']
mat t_stat_2[2,`j']=b2_1[1,`j']/V2_2[1,`j']
}

** P-values
matmap t_stat_1 p_value_1, map(2*ttail(608,abs(@)))
matmap t_stat_2 p_value_2, map(2*ttail(608,abs(@)))

matrix colnames p_value_1 =  Disp_Disp_north Disp_Disp_south Disp_Define  Disp_Farc _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665  _Impio_mpio_837  _cons
matrix colnames p_value_2 =  Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar  _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665 _Impio_mpio_837 _Iid_corre_2 _Iid_corre_3 _Iid_corre_4 _Iid_corre_5 _Iid_corre_6 _Iid_corre_7 _Iid_corre_8 _Iid_corre_9 _Iid_corre_10 _Iid_corre_11 _Iid_corre_12 _Iid_corre_13 _Iid_corre_14 _Iid_corre_15 _Iid_corre_16 _Iid_corre_17 _Iid_corre_18 _Iid_corre_19 _Iid_corre_20 _Iid_corre_21 _Iid_corre_22 _Iid_corre_23 _Iid_corre_24 _Iid_corre_25 _Iid_corre_26 _Iid_corre_27 _Iid_corre_28 _Iid_corre_29 _Iid_corre_30 _Iid_corre_31 _Iid_corre_32 _Iid_corre_33 _Iid_corre_34 _Iid_corre_35 _Iid_corre_36 _Iid_corre_37 _Iid_corre_38 _Iid_corre_39 _Iid_corre_40 _Iid_corre_41 _Iid_corre_42 _Iid_corre_43 _Iid_corre_44 _Iid_corre_45 _Iid_corre_46 _Iid_corre_47 _Iid_corre_48 _Iid_corre_49 _Iid_corre_50 _Iid_corre_51 _Iid_corre_52 _Iid_corre_53 _Iid_corre_54



*** Now OLS 
eststo clear
ereturn clear
local j=1
foreach i in  gini_land gini_owner {
	eststo:  reg `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc _Impio*, cluster(mpio_mpio) robust
	estadd matrix sd2= V1_`j'
	estadd matrix pvalue1= p_value_1[`j',1...]
	eststo:  reg `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar  _Impio* _Iid*, cluster(mpio_mpio) robust	
	estadd matrix sd2= V2_`j'
	estadd matrix pvalue1= p_value_2[`j',1...]
	local j=`j'+1
}

estout using "Munoz_etal_2023-Uraba-Table3.csv", cells(b( fmt(3)) se(par([ ])  star fmt(3)) sd2(par(( ))  pvalue(pvalue1) star fmt(3))) keep(Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar) starlevels(* 0.10 ** 0.05 *** 0.01) label  eqlabels(none)  mlabels(none) collabels(none) style(tab)  delimiter(",")  stats(N r2, fmt(%9.0f  %9.3f)  )


*****************************************************
********************
***** Table 4. Land and Territorial Disputes: Results for Land Gini Indices
********************
*****************************************************


**** SD with spatial correlation
** Eq1
local j=1
foreach i in  prop_mean_size prop_mean_plots {
	cap drop epsilon window dis1 dis2
	x_ols mean_x mean_y cutoff1 cutoff2 `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc _Impio* cons, xreg(13) coord(2)
	mat sp=vecdiag(cov_dep)
	matmap sp V1_`j', map(sqrt(@))
	mat b1_`j'=e(b)
	cap drop epsilon window dis1 dis2
	x_ols mean_x mean_y cutoff1 cutoff2 `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar _Impio* _Iid* cons  , xreg(69) coord(2)
	mat sp=vecdiag(cov_dep)
	matmap sp V2_`j', map(sqrt(@))
	mat b2_`j'=e(b)
	local j=`j'+1
}

forvalue j=1/2 {
matrix colnames V1_`j' =  Disp_Disp_north Disp_Disp_south Disp_Define  Disp_Farc _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665  _Impio_mpio_837  _cons
matrix colnames V2_`j' =  Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar  _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665 _Impio_mpio_837 _Iid_corre_2 _Iid_corre_3 _Iid_corre_4 _Iid_corre_5 _Iid_corre_6 _Iid_corre_7 _Iid_corre_8 _Iid_corre_9 _Iid_corre_10 _Iid_corre_11 _Iid_corre_12 _Iid_corre_13 _Iid_corre_14 _Iid_corre_15 _Iid_corre_16 _Iid_corre_17 _Iid_corre_18 _Iid_corre_19 _Iid_corre_20 _Iid_corre_21 _Iid_corre_22 _Iid_corre_23 _Iid_corre_24 _Iid_corre_25 _Iid_corre_26 _Iid_corre_27 _Iid_corre_28 _Iid_corre_29 _Iid_corre_30 _Iid_corre_31 _Iid_corre_32 _Iid_corre_33 _Iid_corre_34 _Iid_corre_35 _Iid_corre_36 _Iid_corre_37 _Iid_corre_38 _Iid_corre_39 _Iid_corre_40 _Iid_corre_41 _Iid_corre_42 _Iid_corre_43 _Iid_corre_44 _Iid_corre_45 _Iid_corre_46 _Iid_corre_47 _Iid_corre_48 _Iid_corre_49 _Iid_corre_50 _Iid_corre_51 _Iid_corre_52 _Iid_corre_53 _Iid_corre_54
}

** t-stat
mat t_stat_1=J(2,13,0)
forvalue j=1/13 {
mat t_stat_1[1,`j']=b1_1[1,`j']/V1_1[1,`j']
mat t_stat_1[2,`j']=b1_2[1,`j']/V1_2[1,`j']
}
mat t_stat_2=J(2,69,0)
forvalue j=1/13 {
mat t_stat_2[1,`j']=b2_1[1,`j']/V2_1[1,`j']
mat t_stat_2[2,`j']=b2_1[1,`j']/V2_2[1,`j']
}

** P-values
matmap t_stat_1 p_value_1, map(2*ttail(608,abs(@)))
matmap t_stat_2 p_value_2, map(2*ttail(608,abs(@)))

matrix colnames p_value_1 =  Disp_Disp_north Disp_Disp_south Disp_Define  Disp_Farc _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665  _Impio_mpio_837  _cons
matrix colnames p_value_2 =  Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar  _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665 _Impio_mpio_837 _Iid_corre_2 _Iid_corre_3 _Iid_corre_4 _Iid_corre_5 _Iid_corre_6 _Iid_corre_7 _Iid_corre_8 _Iid_corre_9 _Iid_corre_10 _Iid_corre_11 _Iid_corre_12 _Iid_corre_13 _Iid_corre_14 _Iid_corre_15 _Iid_corre_16 _Iid_corre_17 _Iid_corre_18 _Iid_corre_19 _Iid_corre_20 _Iid_corre_21 _Iid_corre_22 _Iid_corre_23 _Iid_corre_24 _Iid_corre_25 _Iid_corre_26 _Iid_corre_27 _Iid_corre_28 _Iid_corre_29 _Iid_corre_30 _Iid_corre_31 _Iid_corre_32 _Iid_corre_33 _Iid_corre_34 _Iid_corre_35 _Iid_corre_36 _Iid_corre_37 _Iid_corre_38 _Iid_corre_39 _Iid_corre_40 _Iid_corre_41 _Iid_corre_42 _Iid_corre_43 _Iid_corre_44 _Iid_corre_45 _Iid_corre_46 _Iid_corre_47 _Iid_corre_48 _Iid_corre_49 _Iid_corre_50 _Iid_corre_51 _Iid_corre_52 _Iid_corre_53 _Iid_corre_54



*** Now OLS 
eststo clear
ereturn clear
local j=1
foreach i in  prop_mean_size prop_mean_plots {
	eststo:  reg `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc _Impio*, cluster(mpio_mpio) robust
	estadd matrix sd2= V1_`j'
	estadd matrix pvalue1= p_value_1[`j',1...]
	eststo:  reg `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar  _Impio* _Iid*, cluster(mpio_mpio) robust	
	estadd matrix sd2= V2_`j'
	estadd matrix pvalue1= p_value_2[`j',1...]
	local j=`j'+1
}

estout using "Munoz_etal_2023-Uraba-Table4.csv", cells(b( fmt(3)) se(par([ ])  star fmt(3)) sd2(par(( ))  pvalue(pvalue1) star fmt(3))) keep(Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar) starlevels(* 0.10 ** 0.05 *** 0.01) label  eqlabels(none)  mlabels(none) collabels(none) style(tab)  delimiter(",")   stats(N r2, fmt(%9.0f  %9.3f)  )


*****************************************************
********************
***** Table 5. Land and Territorial Disputes: Informality of Land Property Rights
********************
*****************************************************


**** SD with spatial correlation
** Eq1
local j=1
foreach i in  indice_informalidad {
	cap drop epsilon window dis1 dis2
	x_ols mean_x mean_y cutoff1 cutoff2 `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc _Impio* cons, xreg(13) coord(2)
	mat sp=vecdiag(cov_dep)
	matmap sp V1_`j', map(sqrt(@))
	mat b1_`j'=e(b)
	cap drop epsilon window dis1 dis2
	x_ols mean_x mean_y cutoff1 cutoff2 `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar _Impio* _Iid* cons  , xreg(69) coord(2)
	mat sp=vecdiag(cov_dep)
	matmap sp V2_`j', map(sqrt(@))
	mat b2_`j'=e(b)
	local j=`j'+1
}

forvalue j=1/1 {
matrix colnames V1_`j' =  Disp_Disp_north Disp_Disp_south Disp_Define  Disp_Farc _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665  _Impio_mpio_837  _cons
matrix colnames V2_`j' =  Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar  _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665 _Impio_mpio_837 _Iid_corre_2 _Iid_corre_3 _Iid_corre_4 _Iid_corre_5 _Iid_corre_6 _Iid_corre_7 _Iid_corre_8 _Iid_corre_9 _Iid_corre_10 _Iid_corre_11 _Iid_corre_12 _Iid_corre_13 _Iid_corre_14 _Iid_corre_15 _Iid_corre_16 _Iid_corre_17 _Iid_corre_18 _Iid_corre_19 _Iid_corre_20 _Iid_corre_21 _Iid_corre_22 _Iid_corre_23 _Iid_corre_24 _Iid_corre_25 _Iid_corre_26 _Iid_corre_27 _Iid_corre_28 _Iid_corre_29 _Iid_corre_30 _Iid_corre_31 _Iid_corre_32 _Iid_corre_33 _Iid_corre_34 _Iid_corre_35 _Iid_corre_36 _Iid_corre_37 _Iid_corre_38 _Iid_corre_39 _Iid_corre_40 _Iid_corre_41 _Iid_corre_42 _Iid_corre_43 _Iid_corre_44 _Iid_corre_45 _Iid_corre_46 _Iid_corre_47 _Iid_corre_48 _Iid_corre_49 _Iid_corre_50 _Iid_corre_51 _Iid_corre_52 _Iid_corre_53 _Iid_corre_54
}

** t-stat
mat t_stat_1=J(1,13,0)
forvalue j=1/13 {
mat t_stat_1[1,`j']=b1_1[1,`j']/V1_1[1,`j']
}
mat t_stat_2=J(1,69,0)
forvalue j=1/13 {
mat t_stat_2[1,`j']=b2_1[1,`j']/V2_1[1,`j']
}

** P-values
matmap t_stat_1 p_value_1, map(2*ttail(608,abs(@)))
matmap t_stat_2 p_value_2, map(2*ttail(608,abs(@)))

matrix colnames p_value_1 =  Disp_Disp_north Disp_Disp_south Disp_Define  Disp_Farc _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665  _Impio_mpio_837  _cons
matrix colnames p_value_2 =  Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar  _Impio_mpio_51 _Impio_mpio_147 _Impio_mpio_172 _Impio_mpio_480 _Impio_mpio_490 _Impio_mpio_659 _Impio_mpio_665 _Impio_mpio_837 _Iid_corre_2 _Iid_corre_3 _Iid_corre_4 _Iid_corre_5 _Iid_corre_6 _Iid_corre_7 _Iid_corre_8 _Iid_corre_9 _Iid_corre_10 _Iid_corre_11 _Iid_corre_12 _Iid_corre_13 _Iid_corre_14 _Iid_corre_15 _Iid_corre_16 _Iid_corre_17 _Iid_corre_18 _Iid_corre_19 _Iid_corre_20 _Iid_corre_21 _Iid_corre_22 _Iid_corre_23 _Iid_corre_24 _Iid_corre_25 _Iid_corre_26 _Iid_corre_27 _Iid_corre_28 _Iid_corre_29 _Iid_corre_30 _Iid_corre_31 _Iid_corre_32 _Iid_corre_33 _Iid_corre_34 _Iid_corre_35 _Iid_corre_36 _Iid_corre_37 _Iid_corre_38 _Iid_corre_39 _Iid_corre_40 _Iid_corre_41 _Iid_corre_42 _Iid_corre_43 _Iid_corre_44 _Iid_corre_45 _Iid_corre_46 _Iid_corre_47 _Iid_corre_48 _Iid_corre_49 _Iid_corre_50 _Iid_corre_51 _Iid_corre_52 _Iid_corre_53 _Iid_corre_54



*** Now OLS 
eststo clear
ereturn clear
local j=1
foreach i in   indice_informalidad  {
	eststo:  reg `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc _Impio*, cluster(mpio_mpio) robust
	estadd matrix sd2= V1_`j'
	estadd matrix pvalue1= p_value_1[`j',1...]
	eststo:  reg `i' Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar  _Impio* _Iid*, cluster(mpio_mpio) robust	
	estadd matrix sd2= V2_`j'
	estadd matrix pvalue1= p_value_2[`j',1...]
	local j=`j'+1
}

estout using "Munoz_etal_2023-Uraba-Table5.csv", cells(b( fmt(3)) se(par([ ])  star fmt(3)) sd2(par(( ))  pvalue(pvalue1) star fmt(3))) keep(Disp_Disp_north Disp_Disp_south Disp_Define Disp_Farc stad_recibidos stad_expulsados  dist_carr dist_mar) starlevels(* 0.10 ** 0.05 *** 0.01) label  eqlabels(none)  mlabels(none) collabels(none) style(tab)  delimiter(",")   stats(N r2, fmt(%9.0f  %9.3f)  )



